import Vue from 'vue'
import Router from 'vue-router'
// 引入多个模块的规则
import approvalsRouter from './modules/approvals.js'
import departmentsRouter from './modules/departments.js'
import employeesRouter from './modules/employees.js'
import permissionRouter from './modules/permission.js'
import attendancesRouter from './modules/attendances.js'
import settingRouter from './modules/setting.js'
import socialRouter from './modules/social.js'
import salarysRouter from './modules/salarys.js'
import userRouter from './modules/user'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
  path: '/login',
  component: () =>
    import ('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () =>
    import ('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () =>
      import ('@/views/dashboard/index'),
    meta: { title: '首页', icon: 'dashboard' }
  }]
},
{
  path: '/import',
  component: Layout,
  hidden: true,
  children: [{
    path: '',
    component: () =>
      import ('@/views/import')
  }]
},
userRouter

// 404 page must be placed at the end !!!
]
// 动态路由
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter

]

const createRouter = () => new Router({
  mode: 'history', // require service support
  base: 'hr/',
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
